package cn.xuqiudong.rpc.spring.provider;

import cn.xuqiudong.rpc.common.constants.ConfigKey;
import cn.xuqiudong.rpc.common.util.PropertiesUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import cn.xuqiudong.rpc.cluster.exception.XqdCommonException;

import java.net.UnknownHostException;

/**
 * 描述: spring 集成xqd rpc的provider入口
 * @author Vic.xu
 * @date 2022-02-24 17:03
 */
@Configuration
public class XqdProviderAutoConfiguration {


    @Bean
    public XqdSpringProviderBeanProcessor xqdSpringProviderBean() throws UnknownHostException {
        Integer port = PropertiesUtils.getInt(ConfigKey.PROTOCOL_PORT_CONFIG);
        if (port == null) {
            throw  new XqdCommonException("Please configure RPC service port number，" + ConfigKey.PROTOCOL_PORT_CONFIG);
        }
        return new XqdSpringProviderBeanProcessor(port.intValue());
    }

}
